package com.project.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.biz.CmsShoppingCartProductSkuBiz;
import com.project.entity.CmsProductSku;
import com.project.entity.CmsShoppingCartProductSku;
import com.project.mapper.CmsShoppingCartProductSkuMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @Description: 购物车产品SKU业务层接口实现类
 * @Author: zhuchi
 * @CreateDate: 2020/10/16 19:21
 * @Version: 1.0
 */
@Service
public class CmsShoppingCartProductSkuBizImpl extends ServiceImpl<CmsShoppingCartProductSkuMapper, CmsShoppingCartProductSku> implements CmsShoppingCartProductSkuBiz {

    /**
     * 添加购物车产品SKU
     * @param cartId
     * @param cmsProductSku
     * @return
     */
    public int addShoppingCartProductSku(Long cartId, CmsProductSku cmsProductSku){
        CmsShoppingCartProductSku shoppingCartProductSku = new CmsShoppingCartProductSku();
        BeanUtils.copyProperties(cmsProductSku, shoppingCartProductSku);
        shoppingCartProductSku.setCartId(cartId);
        return this.baseMapper.insert(shoppingCartProductSku);
    }

    /**
     * 根据购物车ID删除购物车产品SKU
     * @param cartId
     * @return
     */
    public int delShoppingCartProductSku(Long cartId){
        QueryWrapper<CmsShoppingCartProductSku> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cart_id", cartId);
        return this.baseMapper.delete(queryWrapper);
    }

}
